<?php
// This php file implements the header part of the page
// Also the create new Task for a project page
session_start();

$_SESSION['iframe'] = 0;
if (!isset($_SESSION['user'])) {
    echo "<script > window.location.href='index.php';</script>";
}
?>
<!DOCTYPE html />
<html  xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <meta http-equiv="X-UA-Compatible" content="IE=8" />
        <meta name="viewport" content="width=1024" />

        <meta name="author" content="RestartIT LTD - web developing | Shiran & Miri | "/>
        <meta name="description" content="" />
        <meta name="keywords" content="" />

        <!-- css implanting--->
        <link href="style/demoStyles.css" rel="stylesheet" type="text/css" />
        <link href="style/jscrollpane.css" rel="stylesheet" type="text/css" />
        <link href="style/style.css" rel="stylesheet" type="text/css" />
        <link rel="icon"  type="image/png" href="style/images/icon_small.png"  />


        <!-- js implanting-->
        <script src="inc/js/jquery-1.7.min.js"  type="text/javascript"></script>
        <script src="inc/js/jquery-ui-1.8.17.custom.min.js"  type="text/javascript"></script>

        <script src="inc/js/core.js" type="text/javascript"></script>
        <script src="inc/js/jquery.mousewheel.js" type="text/javascript"></script>
        <script src="inc/js/jscrollpane.min.js" type="text/javascript"></script>
        <script src="inc/js/restart_crm.js" type="text/javascript"></script>
        <script src="inc/js/jquery.validate.js" type="text/javascript"></script>
        <title>RestartIT CRM</title>

    </head>
    <body>
<?php
require_once('./config.php');
require_once('./inc/database.php');
require_once('./inc/functions.php');
require_once('./class/baseDB.php');
require_once('./class/class.user.php');
require_once('./class/class.project.php');
require_once('./class/class.task.php');
require_once('./class/class.project_access_details.php');
require_once('./class/class.permissions.php');
require_once('./class/class.comments.php');
require_once('./class/class.dashboard.php');
require_once('./class/class.customer.php');


$user_session = new user();
$user_session->getby_name($_SESSION['user']);

function gettime() {
    $arrtime = localtime(time(), true);

    $s = $arrtime['tm_hour'] . ':' . $arrtime['tm_min'];
    return $s;
}
?>
        <div id="wrapper"><!-- wraps the site and puts it in the middle-->

            <div id="lightbox"></div>S
            <div id="lightbox_frame">
                <div id="lightbox_content">
                                
                    <div id="add_task"><!-- add new task form -->
                        <h3>יצירת פנייה חדשה לפרוייקט <span class="color_turkiz"></span></h3>
                        <form id="new_task" name="new_task">
<?php $id_user_session = $user_session->getuser_id(); ?>
                            <input id="hid_id_user" name="hid_id_user" type="hidden" value="<?php echo $id_user_session ?>"  />
                            <div id="textarea_frame">
                                <textarea id="content_textarea" name="content_textarea" onfocus="if (this.value == 'הקלידו את תוכן הפנייה...') {
                        this.value = '';
                    }" onblur="if (this.value == '') {
                        this.value = 'הקלידו את תוכן הפנייה...';
                    }">הקלידו את תוכן הפנייה...</textarea>
                            </div>

                            <div id="link_frame">
                                <label for="inp_link" class="color_turkiz">קישור רלוונטי:</label>
                                <input id="inp_link" name="inp_link" type="text" />
                            </div>

                            <div id="select_frame">
                                <select id="Browser" name="Browser">
                                    <option value="none">דפדפן</option>
                                    <option value="1">כל הדפדפנים</option>
                                    <option value="2">firefox</option>
                                    <option value="3">chrome</option>
                                    <option value="4">explorer-8</option>
                                    <option value="5">explorer-9</option>
                                    <option value="6">safari</option>
                                </select>
                            </div>

                            <iframe id="iframe_file" scrolling="no" src="<?php echo $CRM_uri ?>iframe.php" ></iframe>

                            <a id="send">שלח</a>
                            <div id="loading"></div>
                        </form>

                    </div>


                </div><!--lightbox_content-->
            </div><!--lightbox_frame-->

            <div id="lightbox_admin"></div><!--lightbox-->
            <div id="lightbox_admin_frame">
                <div id="lightbox_admin_content">


                </div><!--lightbox_admin_content-->
            </div><!--lightbox_admin_frame-->


            <div id="header">
                <a id="logo" href="<?php echo $CRM_uri ?>main.php"></a> <!-- logo link -->

                <!-- top bar show -->
                <div id="top_bar_wrap">
                    <div  id="top_bar" class="topbar" >
                        <span id="hi">שלום <?php echo $user_session->user_name ?>   </span>
                        <div id="time_view">
                            <span>יום <?php
$numday = date('w');
$day = array('ראשון', 'שני', 'שלישי', 'רביעי', 'חמישי', 'שישי', 'שבת');

echo $day[$numday];
$ifSendMailToday = customer::ifSendMailToday(date('o/m/d'));

if ($numday == 0) {
    $ifSendMailToday = customer::ifSendMailToday(date('o/m/d'));
    if ($ifSendMailToday != '1') {
        customer::updatesendWeeklyReport(date('o/m/d'));
    }
}
?>
                            </span>
                            <span><?php echo date('d/m/o'); ?> </span>
                            <span id="time">  
                                <script>
                              function getdate() {

                                  var datatime = new Date();
                                  var minutes = new String(datatime.getMinutes());
                                  if (minutes.length == 2)
                                  {
                                      document.getElementById('time').innerHTML = '   ' + datatime.getHours() + ':' + datatime.getMinutes();
                                  }
                                  else
                                  {
                                      minutes = '0' + minutes;
                                      document.getElementById('time').innerHTML = '   ' + datatime.getHours() + ':' + minutes;
                                  }
                                  setTimeout('getdate();', 500);
                              }
                              getdate();

                                </script>
                            </span>
                        </div>

                        <div id="logout">התנתק מהמערכת</div>
                    </div><!--top_bar-->
                </div><!--top_bar_wrap-->
<!-- main pane -->
<?php if ($user_session->role_type == 1 || $user_session->role_type == 6) { ?> 
                    <div id="control_panel_btn">ניהול</div>
<?php } else { ?>
                    <div id="profil_user">הגדרות פרופיל</div>
                <?php } ?>
                <div id="menu">

                    <div id="mass" >
                        <input id="hid_sound_old" name="hid_sound_old" type="hidden" value="0" />
                        <input id="hid_sound_new" name="hid_sound_new" type="hidden" value="null" />
                        <input id="hid_mass" name="hid_mass"  type="hidden"  value="true" />
                        <input id="hid_user_id" name="hid_user_id" type="hidden" value="<?php echo $user_session->getuser_id(); ?>" />
                        <span id="contect"></span>
                        <span id="bnt">
                            <div id="new_message" ></div>
                        </span>

                    </div>

                    <!-- create task -->
                    <span  id="span_send_task" name="span_send_task"  title="הוספת פנייה " >יצירת פנייה חדשה</span>
<?php if ($user_session->role_type == 1 || $user_session->role_type == 6) { ?>
                        <div id="div_select_customer"> <!-- for admin and sales users  show all customers and select customer field-->
    <?php $arr_customer = project::get_all_customer(); ?>
                            <select id="select_customer" name="select_customer" >
                                <option value="none">בחר חברה</option>
                        <?php foreach ($arr_customer as $key => $value) { ?>
                                    <option value="<?php echo $key ?>"><?php echo $value; ?></option>

    <?php } ?>
                            </select>
                            <span id="select_customer_loader" ></span>
                        </div>
                            <?php } ?>

                    <div id="send_task"></div> <!--send_task--->

                    <!-- find task according to number -->
                    <form id="form_find_task" name="form_find_task" action="">
                        <input id="find_task" name="find_task" type="text" onfocus="if (this.value == 'חיפוש לפי מספר פנייה...') {
                        this.value = ''
                    }" onblur="if (this.value == '') {
                        this.value = 'חיפוש לפי מספר פנייה...'
                    }" value="חיפוש לפי מספר פנייה..." />
                        <a  id="btn" name="btn" class="color_turkiz"></a>
                        <div id="error_find" ></div>
                    </form>


                </div><!--menu-->
            </div><!---header-->

            <script>
                            $(document).ready(function(e) {

                                new_message($('#hid_user_id').val());
                                self.setInterval("new_message($('#hid_user_id').val())", 20000);
                                $('.iframe').live('click', this, function(e) {

                                    var text = '<iframe id="iframe_fileComment" scrolling="no" src="' + $(this).attr("src") + '" ></iframe>';
                                    $(this).removeClass("addFileBTN");
                                    $(this).html(text);
                                });
                                $('#select_customer').change(function(e) {
                                    if ($('#select_customer').val() != 'none')
                                    {

                                        get_all_info_customer($('#select_customer').val());
                                    }
                                });
                                $('#logout').click(function() {
                                    window.location = 'index.php';
                                })

                                $('#mass #bnt, #mass #contect').click(function() {
                                    if ($('#hid_mass').val() == 'true')
                                    {
                                        $('#new_message').slideToggle();
                                    }

                                });
                                $('#profil_user').click(function(e) {
                                    var user_id =<?php echo $user_session->getuser_id(); ?>;
                                    get_edit_profil(user_id);
                                });

                                $('#control_panel_btn').click(function() {
                                    var x = '<?php echo $user_session->role_type; ?>';
                                    if (x == 1 || x == 6)
                                    {
                                        goto_control_panel();
                                    }

                                });
                                $('#send').click(function() {
                                    var temp = $('#new_task').serialize();
                                    var bool = true;
                                    var content_textarea = $('#content_textarea').val();
                                    if (content_textarea == "" || content_textarea == "הקלידו את תוכן הפנייה...")
                                    {
                                        bool = false;
                                        alert('רשום פנייה');
                                    }
                                    if ($('#Browser').val() == 'none') {
                                        alert('בחר סוג דפדפן');
                                        bool = false;
                                    }
                                    if (bool)
                                    {
                                        $('#send_task').slideUp();
                                        send_new_task($('#hid_id_project').val(), $('#hid_id_user').val(), temp);
                                    }
                                });

                                $("#span_send_task").click(function(e) {
                                    $("#lightbox, #lightbox_frame, #add_task").show();
                                    $('#add_task input[type="text"]').val('');
                                    $('#add_task textarea').val('הקלידו את תוכן הפנייה...');
                                });
                                $("#lightbox, #lightbox_admin").click(function(e) {
                                    $("#lightbox, #lightbox_admin, #lightbox_frame, #lightbox_admin_frame").hide();
                                });

                                $('#find_task').bind('keypress', function(a) {
                                    if (a.which == 13)
                                    {
                                        $('#form_find_task').submit();

                                    }
                                });
                                $('#form_find_task #btn').click(function(e) {
                                    $('#form_find_task').submit();
                                });
                                $("#form_find_task").validate({
                                    rules: {find_task: {required: true, digits: true}},
                                    messages: {find_task: "הפנייה מורכבת ממספרים בלבד"},
                                    errorLabelContainer: '#error_find',
                                    errorElement: "li",
                                    submitHandler: function(form)
                                    {
                                        find_for_task($('#form_find_task #find_task').val());
                                    }
                                });
                            });

            </script>

